package io.renren.service.impl;

import com.alibaba.fastjson.JSONObject;
import io.renren.dao.PersonDispatchDao;
import io.renren.dao.RefundContractDao;
import io.renren.dao.RefundDao;
import io.renren.entity.PersonDispatchEntity;
import io.renren.entity.RefundContractEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import io.renren.dao.SocialSecurityPayDetailDao;
import io.renren.entity.SocialSecurityPayDetailEntity;
import io.renren.service.SocialSecurityPayDetailService;



@Service("socialSecurityPayDetailService")
public class SocialSecurityPayDetailServiceImpl implements SocialSecurityPayDetailService {
	@Autowired
	private SocialSecurityPayDetailDao socialSecurityPayDetailDao;
	@Autowired
	private RefundDao refundDao;
	@Autowired
	private PersonDispatchDao personDispatchDao;
	@Autowired
	private RefundContractDao refundContractDao;
	
	@Override
	public SocialSecurityPayDetailEntity queryObject(Integer id){
		return socialSecurityPayDetailDao.queryObject(id);
	}
	
	@Override
	public List<SocialSecurityPayDetailEntity> queryList(Map<String, Object> map){
		return socialSecurityPayDetailDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return socialSecurityPayDetailDao.queryTotal(map);
	}
	
	@Override
	public void save(SocialSecurityPayDetailEntity socialSecurityPayDetail){
		socialSecurityPayDetailDao.save(socialSecurityPayDetail);
	}

	@Override
	public void update(SocialSecurityPayDetailEntity socialSecurityPayDetail){
		socialSecurityPayDetailDao.update(socialSecurityPayDetail);
	}
	
	@Override
	public void delete(Integer id){
		socialSecurityPayDetailDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		socialSecurityPayDetailDao.deleteBatch(ids);
	}

	@Override
	public List<SocialSecurityPayDetailEntity> getInOutList(JSONObject jsonObject) {
		Map<String, Object> map = new HashMap<>();
		Calendar ca = Calendar.getInstance();
		int year = ca.get(Calendar.YEAR);
		int month = ca.get(Calendar.MONTH)+1;
		String id = jsonObject.getString("id");
		PersonDispatchEntity personDispatch = personDispatchDao.queryObject(id);
		map.put("empid",personDispatch.getPersonId());
		map.put("year",year);
		map.put("month",month);
		String type = jsonObject.getString("type");
		List<SocialSecurityPayDetailEntity> list = new ArrayList<>();
		if("payment".equals(type)){//交款
			list = refundDao.getPaymentInfo(map);
		}else if("inoutContact".equals(type)){ //协议退款
			RefundContractEntity entity = refundContractDao.getRefundContractByEmpid(personDispatch.getPersonId());
			if(entity!=null){
				List<String> sslist = new ArrayList<>();
				if(entity.getGongsType().equals("0")){
					sslist.add("socialSecurity03");
				}else if(entity.getYanglType().equals("0")){
					sslist.add("socialSecurity01");
				}else if(entity.getShiyType().equals("0")){
					sslist.add("socialSecurity05");
				}else if(entity.getYilType().equals("0")){
					sslist.add("socialSecurity04");
				}else if(entity.getDabType().equals("0")){
					sslist.add("socialSecurity07");
				}else if(entity.getGongjjType().equals("0")){
					sslist.add("socialSecurity08");
				}
				map.put("list",sslist);
				list = refundDao.getInComeInfoByContract(map);
			}
		}else if("inoutOther".equals(type)){ //其他退款
			list = refundDao.getInComeInfo(map);
		}
		return list;
	}

}
